package com.whut.report;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.whut.model.*;
import com.whut.parMapper.ParProblemCollectDetailMapper;
import com.whut.parMapper.ParProblemDescriptionMapper;
import com.whut.parMapper.ParSystemMapper;
import com.whut.parMapper.utils.MapperUtils;
import com.whut.service.impl.ReportServiceImpl;
import com.whut.utils.FileUtil;
import com.whut.utils.HttpUtil;
import com.whut.utils.MDoc;
import com.whut.utils.pointsCalculate;
import com.whut.v_model.ProblemCollectDetail;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Resource;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class VisualizationReport {
    private ParSystemMapper parSystemMapper;
    private ParProblemDescriptionMapper parProblemDescriptionMapper;
    private ParProblemCollectDetailMapper parProblemCollectDetailMapper;
    private ReportServiceImpl reportServiceImpl;
    @Resource
    private UrlProperties urlProperties;
    @Resource
    private Profiles profiles;
    private MapperUtils mapperUtils;

    private int checkId;
    private int projectId;
    private boolean isNew;
    public static final int WIDTH = 718;
    public static final int HEIGHT = 468;
    public VisualizationReport(ParSystemMapper parSystemMapper,
                               ParProblemDescriptionMapper parProblemDescriptionMapper,
                               ParProblemCollectDetailMapper parProblemCollectDetailMapper,
                               ReportServiceImpl reportServiceImpl,
                               MapperUtils mapperUtils,
                               UrlProperties urlProperties,
                               Profiles profiles
    ) {
        this.parSystemMapper = parSystemMapper;
        this.parProblemDescriptionMapper = parProblemDescriptionMapper;
        this.parProblemCollectDetailMapper = parProblemCollectDetailMapper;
        this.reportServiceImpl = reportServiceImpl;
        this.mapperUtils=mapperUtils;
        this.urlProperties=urlProperties;
        this.urlProperties=urlProperties;
        this.profiles=profiles;
    }

    public String getVisualizationReport(int checkId, int projectId) throws UnsupportedEncodingException {
        DecimalFormat df = new DecimalFormat("0.00");
        Map<String, Object> dataMap = new HashMap<String, Object>();
        reportServiceImpl.initWordDate(dataMap);


        List<String> type3List = new ArrayList<String>();
        type3List.add("2");
        type3List.add("3");
        type3List.add("4");
        //工程概况部分，来自ctp的工程信息
        reportServiceImpl.initProjectSummaryFirstPart(projectId, dataMap);
        //工程概况部分，来自设备信息表的设备信息部分
        List<Equipinfo> equipinfoList = mapperUtils.getEquipinfoMapper().getAllByProjectId(projectId);
        String equip = JSON.toJSONString(equipinfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray equipArray = JSONArray.parseArray(equip);
        List<Object> equipList = new ArrayList<Object>();
        if (equipArray.size() == 0) {
            Map<String, Object> eqMap = new HashMap<String, Object>();
            eqMap.put("equipType", "\\");
            eqMap.put("equipQua", "\\");
            eqMap.put("equipNum", "\\");
            eqMap.put("equipLeaseUnit", "\\");
            eqMap.put("equipUseUnit", "\\");
            eqMap.put("demolitionUnit", "\\");
            eqMap.put("testUnit", "\\");
            equipList.add(eqMap);
        } else {
            for (int i = 0; i < equipArray.size(); i++) {
                Map<String, Object> eqMap = new HashMap<String, Object>();
                JSONObject equipObject = equipArray.getJSONObject(i);
                eqMap.put("equipType", equipObject.getString("equipType"));
                eqMap.put("equipQua", equipObject.getString("equipQua"));
                eqMap.put("equipNum", equipObject.getString("equipNum"));
                eqMap.put("equipLeaseUnit", equipObject.getString("equipLeaseUnit"));
                eqMap.put("equipUseUnit", equipObject.getString("equipUseUnit"));
                eqMap.put("demolitionUnit", equipObject.getString("demolitionUnit"));
                eqMap.put("testUnit", equipObject.getString("testUnit"));
                equipList.add(eqMap);
            }
        }
        dataMap.put("equipList", equipList);

        //第一部分 安全综合评价 （一）模糊数学安全综合评价结果
        Fuzzyresult aqFuzzyResult = mapperUtils.getFuzzyresultMapper().selectInfoByCheckIdAndTypeAndNumber(checkId, 1, 1, -1);
        List<Double> allRiskList = new ArrayList<>();
        allRiskList.add(aqFuzzyResult.getRisk1Point());
        allRiskList.add(aqFuzzyResult.getRisk2Point());
        allRiskList.add(aqFuzzyResult.getRisk3Point());
        allRiskList.add(aqFuzzyResult.getRisk4Point());
        allRiskList.add(aqFuzzyResult.getRisk5Point());
        int allOverMaxIndex = allRiskList.lastIndexOf(Collections.max(allRiskList));
        String alloverRiskResult = "";
        switch (allOverMaxIndex) {
            case 0:
                alloverRiskResult = "\"安全\"";
                break;
            case 1:
                alloverRiskResult = "\"轻微风险\"";
                break;
            case 2:
                alloverRiskResult = "\"较大风险\"";
                break;
            case 3:
                alloverRiskResult = "\"重大风险\"";
                break;
            case 4:
                alloverRiskResult = "\"特别重大风险\"";
                break;
            default:
        }
        String fuzzyConclusion = "该项目安全实体风险等级" + "{" + "\"安全\"" + "\"轻微风险\"" +
                "\"较大风险\"" + "\"重大风险\"" + "\"特别重大风险\"" + "}" + "程度分别为{" + aqFuzzyResult.getRisk1Point() + "," + aqFuzzyResult.getRisk2Point() + ","
                + aqFuzzyResult.getRisk3Point() + "," + aqFuzzyResult.getRisk4Point() + "," + aqFuzzyResult.getRisk5Point() + "},依据最大隶属度原则,该项目风险状态隶属于" + alloverRiskResult;
        dataMap.put("fuzzyConclusion", fuzzyConclusion);
        try {
            HashMap<String, String> radarMap = new HashMap<>();
            Object[] radarData0 = new Object[]{aqFuzzyResult.getRisk1Point(), aqFuzzyResult.getRisk2Point(), aqFuzzyResult.getRisk3Point(), aqFuzzyResult.getRisk4Point(), aqFuzzyResult.getRisk5Point()};
            Object[] radarData1 = new Object[]{aqFuzzyResult.getRisk1Point(), "", "", "", ""};
            Object[] radarData2 = new Object[]{"", aqFuzzyResult.getRisk2Point(), "", "", ""};
            Object[] radarData3 = new Object[]{"", "", aqFuzzyResult.getRisk3Point(), "", ""};
            Object[] radarData4 = new Object[]{"", "", "", aqFuzzyResult.getRisk4Point(), ""};
            Object[] radarData5 = new Object[]{"", "", "", "", aqFuzzyResult.getRisk5Point()};
            Object[] radarData6 = new Object[]{"", "", "", "", ""};
            HashMap<String, Object> radarInfoMap = new HashMap<>();
            radarInfoMap.put("data0", radarData0);
            radarInfoMap.put("data1", radarData1);
            radarInfoMap.put("data2", radarData2);
            radarInfoMap.put("data3", radarData3);
            radarInfoMap.put("data4", radarData4);
            radarInfoMap.put("data5", radarData5);
            radarInfoMap.put("data6", radarData6);
            radarMap.put("dataSet", JSON.toJSONString(radarInfoMap));
            radarMap.put("height", "468");
            radarMap.put("width", "718");
            radarMap.put("index", "5");
            String radarPic = HttpUtil.post("http://localhost:3000/echarts", radarMap, "utf-8");
            dataMap.put("radarPic", radarPic.substring(22));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //（二）、项目安全风险分布
        int allProblemNum = parProblemCollectDetailMapper.getAllNum(checkId);
        int txNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "提醒");
        int oneNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "1");
        int twoNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "2");
        int threeNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "3");
        int fourNum = parProblemCollectDetailMapper.getAllRiskPointCountByType(checkId, "4");
        dataMap.put("txNum", txNum);
        dataMap.put("oneNum", oneNum);
        dataMap.put("twoNum", twoNum);
        dataMap.put("threeNum", threeNum);
        dataMap.put("fourNum", fourNum);
        String txPercent = pointsCalculate.caculateToPercent(txNum, allProblemNum);
        String onePercent = pointsCalculate.caculateToPercent(oneNum, allProblemNum);
        String twoPercent = pointsCalculate.caculateToPercent(twoNum, allProblemNum);
        String threePercent = pointsCalculate.caculateToPercent(threeNum, allProblemNum);
        String fourPercent = pointsCalculate.caculateToPercent(fourNum, allProblemNum);
        dataMap.put("txPercent", txPercent);
        dataMap.put("onePercent", onePercent);
        dataMap.put("twoPercent", twoPercent);
        dataMap.put("threePercent", threePercent);
        dataMap.put("fourPercent", fourPercent);
        dataMap.put("allProblemNum", allProblemNum);
        try {
            HashMap<String, String> riskPieMap = new HashMap<>();
            Map<String, Object> riskPieMaps = new HashMap<>();
            Map<String, Object> riskPieMap0 = new HashMap<>();
            riskPieMap0.put("name", "提醒");
            riskPieMap0.put("y", txNum);
            riskPieMap0.put("sliced", true);
            riskPieMap0.put("color", "rgb(46,232,65)");
            Map<String, Object> riskPieMap1 = new HashMap<>();
            riskPieMap1.put("name", "特征值1");
            riskPieMap1.put("y", oneNum);
            riskPieMap1.put("sliced", true);
            riskPieMap1.put("color", "rgb(49,95,232)");
            Map<String, Object> riskPieMap2 = new HashMap<>();
            riskPieMap2.put("name", "特征值2");
            riskPieMap2.put("y", twoNum);
            riskPieMap2.put("sliced", true);
            riskPieMap2.put("color", "rgb(232,232,49)");
            Map<String, Object> riskPieMap3 = new HashMap<>();
            riskPieMap3.put("name", "特征值3");
            riskPieMap3.put("y", threeNum);
            riskPieMap3.put("sliced", true);
            riskPieMap3.put("color", "rgb(240,117,60)");
            Map<String, Object> riskPieMap4 = new HashMap<>();
            riskPieMap4.put("name", "特征值4");
            riskPieMap4.put("y", fourNum);
            riskPieMap4.put("sliced", true);
            riskPieMap4.put("color", "rgb(232,36,18)");
            Object[] riskPieInfo = new Object[]{riskPieMap0, riskPieMap1, riskPieMap2, riskPieMap3, riskPieMap4};
            riskPieMaps.put("data", riskPieInfo);
            riskPieMaps.put("title", "项目安全风险分布饼图");
            riskPieMap.put("dataSet", JSON.toJSONString(riskPieMaps));
            riskPieMap.put("height", "468");
            riskPieMap.put("width", "718");
            riskPieMap.put("index", "2");
            String riskPiePic = HttpUtil.post("http://localhost:3000/highcharts", riskPieMap, "utf-8");
            dataMap.put("riskPiePic", riskPiePic.substring(22));
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            HashMap<String, String> riskBarMap = new HashMap<>();
            Map<String, Object> riskBarInfos = new HashMap<>();
            Map<String, Object> riskBarInfo0 = new HashMap<>();
            riskBarInfo0.put("name", "提醒");
            riskBarInfo0.put("color", "rgb(46,232,65)");
            riskBarInfo0.put("data", new Integer[]{txNum});
            Map<String, Object> riskBarInfo1 = new HashMap<>();
            riskBarInfo1.put("name", "特征值1");
            riskBarInfo1.put("color", "rgb(49,95,232)");
            riskBarInfo1.put("data", new Integer[]{oneNum});
            Map<String, Object> riskBarInfo2 = new HashMap<>();
            riskBarInfo2.put("name", "特征值2");
            riskBarInfo2.put("color", "rgb(232,232,49)");
            riskBarInfo2.put("data", new Integer[]{twoNum});
            Map<String, Object> riskBarInfo3 = new HashMap<>();
            riskBarInfo3.put("name", "特征值3");
            riskBarInfo3.put("color", "rgb(240,117,60)");
            riskBarInfo3.put("data", new Integer[]{threeNum});
            Map<String, Object> riskBarInfo4 = new HashMap<>();
            riskBarInfo4.put("name", "特征值4");
            riskBarInfo4.put("color", "rgb(232,36,18)");
            riskBarInfo4.put("data", new Integer[]{fourNum});
            Object[] riskBarInfo = new Object[]{riskBarInfo0, riskBarInfo1, riskBarInfo2, riskBarInfo3, riskBarInfo4};
            riskBarInfos.put("series", riskBarInfo);
            riskBarInfos.put("title", "项目安全风险分布直方图");
            riskBarMap.put("dataSet", JSON.toJSONString(riskBarInfos));
            riskBarMap.put("height", "468");
            riskBarMap.put("width", "718");
            riskBarMap.put("index", "3");
            String riskBarPic = HttpUtil.post("http://localhost:3000/highcharts", riskBarMap, "utf-8");
            dataMap.put("riskBarPic", riskBarPic.substring(22));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //第一部分，（二）分项评估结果
        Integer taskId = mapperUtils.getContractchecktaskMapper().getTaskIdByCheckId(checkId);
        List<String> allBarCategories = new ArrayList<>();
        List<Double> allBarData0 = new ArrayList<>();
        List<Double> allBarData1 = new ArrayList<>();
        List<Double> allBarData2 = new ArrayList<>();

        List<String> aqResultBarCategories = new ArrayList<>();
        List<Integer> aqResultBarData0 = new ArrayList<>();
        List<Integer> aqResultBarData1 = new ArrayList<>();
        List<Double> aqResultBarData2 = new ArrayList<>();

        List<String> glResultBarCategories = new ArrayList<>();
        List<Integer> glResultBarData0 = new ArrayList<>();
        List<Integer> glResultBarData1 = new ArrayList<>();
        List<Double> glResultBarData2 = new ArrayList<>();

        String ZJname1 = "[1]";
        double allsecondPoint = 0;
        JSONArray ZJname1Array = JSONArray.parseArray(ZJname1);
        float allExtraPointFloat = parProblemCollectDetailMapper.getAllExtraPoint(checkId);
        double allExtraPoint = Double.valueOf(String.valueOf(allExtraPointFloat));
        double overAllPoint = 0;
        List<Object> part2List = new ArrayList<Object>();
        String Name1 = "";
        double allweight1 = 0;
        for (int i = 0; i < ZJname1Array.size(); i++) {
            double Tweight1 = 0;
            String weight1 = parSystemMapper.getWeight1ByName1(parSystemMapper.getName4ByName4Id(ZJname1Array.getIntValue(i)));
            Tweight1 = pointsCalculate.getPercentInstance(weight1);
            allweight1 += Tweight1;
        }
        for (int k = 0; k < ZJname1Array.size(); k++) {
            Map<String, Object> part2Map = new HashMap<String, Object>();
            List<Object> part2InnerList = new ArrayList<Object>();
            String pName1 = parSystemMapper.getName4ByName4Id(ZJname1Array.getIntValue(k));
            double Tweight1 = 0;
            String weight1 = parSystemMapper.getWeight1ByName1(pName1);
            Tweight1 = pointsCalculate.getPercentInstance(weight1);
            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                dataMap.put("aqLever", pointsCalculate.getMaxRiskPoint(list));
                Name1 = "安全文明";
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                dataMap.put("zlLever", pointsCalculate.getMaxRiskPoint(list));
                Name1 = "质量风险";
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                List<ProblemCollectDetail> list = parProblemCollectDetailMapper.getAllInfoByName1(checkId, pName1);
                dataMap.put("glLever", pointsCalculate.getMaxRiskPoint(list));
                Name1 = "管理行为";
            }
            part2Map.put("name1No", k + 1);
            part2Map.put("name1", Name1);
            List<Object> secondIdList = parProblemCollectDetailMapper.getSecondId(checkId, pName1);
            String secondIdInfo = JSON.toJSONString(secondIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray secondIdInfoArray = JSONArray.parseArray(secondIdInfo);
            double allweight2 = 0;
            for (int p = 0; p < secondIdInfoArray.size(); p++) {
                int allsecondId = secondIdInfoArray.getIntValue(p);
                String weight2 = parSystemMapper.getWeight3ByThirdId(allsecondId);
                double weight22 = pointsCalculate.getPercentInstance(weight2);
                allweight2 += weight22;
            }
            for (int u = 0; u < secondIdInfoArray.size(); u++) {
                int secondId = secondIdInfoArray.getIntValue(u);
                double weight222 = 0;
                String weight2 = parSystemMapper.getWeight3ByThirdId(secondId);
                weight222 = pointsCalculate.getPercentInstance(weight2);
                List<ProblemCollectDetail> fourthPoints = parProblemCollectDetailMapper.getFourthPoint(checkId, pName1, secondId);
                String fourthCalculateInfo = JSON.toJSONString(fourthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray fourthPointsCalculateArray = JSONArray.parseArray(fourthCalculateInfo);
                double point = 0;
                /*double allweight4 = 0;
                for (int v = 0; v < fourthPointsCalculateArray.size(); v++) {
                    JSONObject jsonObject = fourthPointsCalculateArray.getJSONObject(v);
                    double Tweight4 = 0;
                    int fourthId = jsonObject.getIntValue("fourthId");
                    String trueweight4 = parSystemMapper.getWeight3ByThirdId(fourthId);
                    Tweight4 = pointsCalculate.getPercentInstance(trueweight4);
                    allweight4 += Tweight4;
                }*/
                for (int j = 0; j < fourthPointsCalculateArray.size(); j++) {
                    Map<String, Object> part2InnerMap = new HashMap<String, Object>();
                    JSONObject part2InnerObject = fourthPointsCalculateArray.getJSONObject(j);
                    double allweight4 = 0;
                    List<ProblemCollectDetail> countFourthWeight = parProblemCollectDetailMapper.getAllFourthInfoMXTQ(checkId, part2InnerObject.getIntValue("thirdId"));
                    for (int v = 0; v < countFourthWeight.size(); v++) {
                        double Tweight4 = 0;
                        int fourthId = countFourthWeight.get(v).getFourthId();
                        String newWeight4 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(fourthId, taskId);
                        if (StringUtils.isNotBlank(newWeight4)) {
                            Tweight4 = pointsCalculate.getPercentInstance(newWeight4);
                        } else {
                            String trueweight4 = parSystemMapper.getWeight3ByThirdId(fourthId);
                            Tweight4 = pointsCalculate.getPercentInstance(trueweight4);
                        }
                        allweight4 += Tweight4;
                    }
                    part2InnerMap.put("pName4", part2InnerObject.getString("pName4"));
                    aqResultBarCategories.add(part2InnerObject.getString("pName4"));
                    double weight3 = 0;
                    double weight4 = 0;
                    int part2FourthId = part2InnerObject.getIntValue("fourthId");
                    int part2InnerProblemNum = parProblemCollectDetailMapper.getProblemNumByFourthId(checkId, part2FourthId);
                    int riskPointOver3Num = parProblemCollectDetailMapper.getProblemNumOver3(checkId, part2FourthId, type3List);
                    aqResultBarData0.add(part2InnerProblemNum);
                    aqResultBarData1.add(riskPointOver3Num);
                    part2InnerMap.put("problemNum", part2InnerProblemNum);
                    part2InnerMap.put("riskPointNum", riskPointOver3Num);
                    int part2ThirdId = part2InnerObject.getIntValue("thirdId");

                    //更改权重来源
                    String newWeight4 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(part2FourthId, taskId);
                    if (StringUtils.isNotBlank(newWeight4)) {
                        weight4 = pointsCalculate.getPercentInstance(newWeight4);
                    } else {
                        weight4 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight4"));
                    }

                    String newWeight3 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(part2ThirdId, taskId);
                    if (StringUtils.isNotBlank(newWeight3)) {
                        weight3 = pointsCalculate.getPercentInstance(newWeight3);
                    } else {
                        weight3 = pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
                    }

                    part2InnerMap.put("weight4", pointsCalculate.double2ToPercent(weight3, allweight4 / weight4));
                    List<ProblemCollectDetail> sixthPoints = parProblemCollectDetailMapper.getsixthPoints(checkId, part2FourthId);
                    String pointName6Info = JSON.toJSONString(sixthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                    JSONArray sixthPointsArray = JSONArray.parseArray(pointName6Info);
                    double calculatePoint6 = 0;
                    double calculatePoint66 = 0;
                    double calculateTruePoint = 0;
                    for (int y = 0; y < sixthPointsArray.size(); y++) {
                        JSONObject sixPointObject = sixthPointsArray.getJSONObject(y);
                        int deductSixthId = sixPointObject.getIntValue("sixthId");
                        float deductPointsSumFloat = parProblemCollectDetailMapper.getdeductSum(checkId, deductSixthId);
                        double deductPointsSum = Double.valueOf(String.valueOf(deductPointsSumFloat));
                        double truePoint = Double.parseDouble(sixPointObject.getString("point6"));
                        if (truePoint <= deductPointsSum) {
                            calculatePoint66 = 0;
                        } else {
                            calculatePoint66 = truePoint - deductPointsSum;
                        }
                        calculateTruePoint += truePoint;
                        calculatePoint6 += calculatePoint66;
                    }
                    double noProblemPoint = 0;
                    List<Object> noProblemSixthIdList = mapperUtils.getUncheckeditemsMapper().getNoProblemSixthId(checkId, part2InnerObject.getIntValue("fourthId"));
                    String noProblemSixthIdInfo = JSON.toJSONString(noProblemSixthIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                    JSONArray noProblemSixthArray = JSONArray.parseArray(noProblemSixthIdInfo);
                    for (int m = 0; m < noProblemSixthArray.size(); m++) {
                        int noProblemSixthId = noProblemSixthArray.getIntValue(m);
                        double noProblem = Double.parseDouble(parSystemMapper.getPoint4ByPoint4Id(noProblemSixthId));
                        noProblemPoint += noProblem;
                    }
                    double checkItemPoint = (calculatePoint6 + noProblemPoint) / (calculateTruePoint + noProblemPoint) * 100;
                    List<ProblemCollectDetail> checkItemCalcuList = parProblemCollectDetailMapper.getAllFourthInfo(checkId, part2FourthId);
                    String maxFourthRiskPoint = pointsCalculate.getMaxRiskPoint(checkItemCalcuList);
                    int maxFourthRiskPointNum = parProblemCollectDetailMapper.getRiskPointCount(checkId, part2FourthId, maxFourthRiskPoint);
                    double limitFourhPoint = Double.parseDouble((mapperUtils.getPointlimitMapper().getLimitPointByInfo(String.valueOf(maxFourthRiskPointNum), maxFourthRiskPoint)) == null ? "100" : mapperUtils.getPointlimitMapper().getLimitPointByInfo(String.valueOf(maxFourthRiskPointNum), maxFourthRiskPoint));
                    if (checkItemPoint > limitFourhPoint) {
                        checkItemPoint = limitFourhPoint;
                    }
                    String s = df.format(checkItemPoint);
                    aqResultBarData2.add(Double.parseDouble(s));
                    part2InnerMap.put("checkItemPoint", s);
                    int allPointSaveFourthPointCount = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, part2FourthId);
                    if (allPointSaveFourthPointCount != 0) {
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                        Date date1 = new Date(System.currentTimeMillis());
                        String lastEditTime = formatter.format(date1);
                        mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, s, part2FourthId, lastEditTime);
                    } else {
                        Allpointsave allpointsave = new Allpointsave();
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                        Date date1 = new Date(System.currentTimeMillis());
                        allpointsave.setNewCreateTime(formatter.format(date1));
                        allpointsave.setLastEditTime(formatter.format(date1));
                        allpointsave.setProjectId(projectId);
                        allpointsave.setCheckId(checkId);
                        allpointsave.setNumber(part2FourthId);
                        allpointsave.setPoint(s);
                        mapperUtils.getAllpointsaveMapper().insert(allpointsave);
                    }
                    //point += checkItemPoint * weight3 / countFourthId;
                    point += checkItemPoint * weight3 / (allweight4 / weight4);
                    part2InnerList.add(part2InnerMap);
                }

                //添加无问题项
                List<ProblemCollectDetail> noProblemItemList = new ArrayList<>();
                List<Noproblemitem> noProblemFourthId= mapperUtils.getNoproblemitemMapper().getFourthIdList(checkId,secondId);
                for (Noproblemitem noproblemitem : noProblemFourthId){
                    ProblemCollectDetail pcd = new ProblemCollectDetail();
                    pcd.setFourthId(noproblemitem.getFourthId());
                    pcd.setThirdId(noproblemitem.getThirdId());
                    String weight3= parSystemMapper.getWeight3ByThirdId(noproblemitem.getThirdId());
                    String weight4= parSystemMapper.getWeight3ByThirdId(noproblemitem.getFourthId());
                    pcd.setWeight3(weight3);
                    pcd.setWeight4(weight4);
                    String pName4 = parSystemMapper.getName4ByName4Id(noproblemitem.getFourthId());
                    pcd.setpName4(pName4);
                    pcd.setPoint3(parSystemMapper.getPoint4ByPoint4Id(noproblemitem.getThirdId()));
                    pcd.setPoint4(parSystemMapper.getPoint4ByPoint4Id(noproblemitem.getFourthId()));
                    noProblemItemList.add(pcd);
                }
//                List<ProblemCollectDetail> noProblemItemList = parProblemCollectDetailMapper.getNoProblemItem(checkId, secondId);
                String noProblemCalculateInfo = JSON.toJSONString(noProblemItemList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray noProblemCalculateArray = JSONArray.parseArray(noProblemCalculateInfo);
                for (int j = 0; j < noProblemCalculateArray.size(); j++) {
                    Map<String, Object> part2InnerMap = new HashMap<String, Object>();
                    JSONObject part2InnerObject = noProblemCalculateArray.getJSONObject(j);
                    Double point4=Double.parseDouble(part2InnerObject.getString("point4"));
                    point += point4*pointsCalculate.getPercentInstance(part2InnerObject.getString("weight3"));
                    part2InnerMap.put("pName4", noProblemItemList.get(j).getpName4());
                    part2InnerMap.put("weight4",part2InnerObject.getString("weight3"));
                    part2InnerMap.put("checkItemPoint", part2InnerObject.getString("point4"));
                    part2InnerList.add(part2InnerMap);
                }

                List<Object> getThirdId = parProblemCollectDetailMapper.getThirdId(checkId, pName1, secondId);
                String thirdIdInfo = JSON.toJSONString(getThirdId, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray thirdArray = JSONArray.parseArray(thirdIdInfo);
                /*thirdArray中还需要加入无问题项的内容*/
                List<Object> noProblemThirdId= mapperUtils.getNoproblemitemMapper().getThirdIdList(checkId,secondId);
                for (Object obj : noProblemThirdId){
                    thirdArray.add(obj);
                }
                double allweight3 = 0;
                for (int v = 0; v < thirdArray.size(); v++) {
                    double Tweight3 = 0;
                    int thirdId = thirdArray.getIntValue(v);
                    String newWeight3 = mapperUtils.getEditableweightpsMapper().getWeightByNumber(thirdId, taskId);
                    if (StringUtils.isNotBlank(newWeight3)) {
                        Tweight3 = pointsCalculate.getPercentInstance(newWeight3);
                    } else {
                        String trueweight3 = parSystemMapper.getWeight3ByThirdId(thirdId);
                        Tweight3 = pointsCalculate.getPercentInstance(trueweight3);
                    }
                    allweight3 += Tweight3;
                }
                double thirdPoint = Double.parseDouble(df.format(point / allweight3));
                double percent2 = Double.parseDouble(df.format(weight222 / allweight2));
                double secondPoint = Double.parseDouble(df.format(thirdPoint * percent2));
                allsecondPoint += secondPoint;
            }
            if (pName1.equals("安全检查")||pName1.equals("新安全检查")) {
                dataMap.put("aqPoint", allsecondPoint);
            } else if (pName1.equals("质量检查")||pName1.equals("新质量检查")) {
                dataMap.put("zlPoint", allsecondPoint);
            } else if (pName1.equals("管理行为")||pName1.equals("新管理行为")) {
                dataMap.put("glPoint", allsecondPoint);
            }
            int firstPointCount = mapperUtils.getAllpointsaveMapper().getAllPointCountByCheckId(checkId, 1);
            if (firstPointCount != 0) {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date1 = new Date(System.currentTimeMillis());
                String lastEditTime = formatter.format(date1);
                mapperUtils.getAllpointsaveMapper().updateAllPoint(checkId, df.format(allsecondPoint), 1, lastEditTime);
            } else {
                Allpointsave allpointsave = new Allpointsave();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date1 = new Date(System.currentTimeMillis());
                allpointsave.setNewCreateTime(formatter.format(date1));
                allpointsave.setLastEditTime(formatter.format(date1));
                allpointsave.setCheckId(checkId);
                allpointsave.setNumber(1);
                allpointsave.setPoint(df.format(allsecondPoint));
                allpointsave.setProjectId(projectId);
                mapperUtils.getAllpointsaveMapper().insert(allpointsave);
            }
            double trueWeight1 = Double.parseDouble(df.format(Tweight1 / allweight1));
            overAllPoint += Double.parseDouble(df.format(trueWeight1 * allsecondPoint));
            part2Map.put("point", allsecondPoint);
            part2Map.put("part2InnerList", part2InnerList);
            part2List.add(part2Map);
        }
        List<ProblemCollectDetail> overallList = parProblemCollectDetailMapper.getAllProblemCollectInfoByCheckId(checkId);
        ContractTaskProject contractTaskProjectRiskPoint = new ContractTaskProject();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date1 = new Date(System.currentTimeMillis());
        contractTaskProjectRiskPoint.setLastEditTime(formatter.format(date1));
        contractTaskProjectRiskPoint.setProjectId(projectId);
        contractTaskProjectRiskPoint.setLatestRiskLevel(pointsCalculate.getMaxRiskPoint(overallList));
        mapperUtils.getContractTaskProjectMapper().updateByPrimaryKeySelective(contractTaskProjectRiskPoint);
        ContractTaskProject newRiskList = mapperUtils.getContractTaskProjectMapper().selectByPrimaryKey(projectId);
        String finishTime = mapperUtils.getContractchecktaskMapper().getFinishTimeByCheckId(checkId);
        if (newRiskList.getCheckTime().equals("") || newRiskList.getCheckTime().compareTo(finishTime) <= 0) {
            try {
                ContractTaskProject contracttaskproject = new ContractTaskProject();
                contracttaskproject.setLastEditTime(formatter.format(date1));
                contracttaskproject.setProjectId(projectId);
                contracttaskproject.setLatestCheckTime(finishTime);
                mapperUtils.getContractTaskProjectMapper().updateByPrimaryKeySelective(contracttaskproject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        dataMap.put("part2List", part2List);


        //综合评估结果
        List<Object> ZJList = new ArrayList<Object>();
        List<Integer> ZJaqFourthIdList = parProblemCollectDetailMapper.getAllFourthIdByCheckIdAndFirstId(checkId, 736);
        for (int j = 0; j < ZJaqFourthIdList.size(); j++) {
            double ZJallOverPoint = 0;
            allBarData2.add(allsecondPoint);
            Map<String, Object> ZJMap = new HashMap<>();
            int ZJpart2FourthId = ZJaqFourthIdList.get(j);
            ZJMap.put("No", j + 1);
            ZJMap.put("pName4", parSystemMapper.getName4ByName4Id(ZJpart2FourthId));
            allBarCategories.add(parSystemMapper.getName4ByName4Id(ZJpart2FourthId));
            glResultBarCategories.add(parSystemMapper.getName4ByName4Id(ZJpart2FourthId));
            int problemNum = parProblemCollectDetailMapper.getProblemNumByFourthId(checkId, ZJpart2FourthId);
            ZJMap.put("problemNum", problemNum);
            glResultBarData0.add(problemNum);
            int riskPoint = parProblemCollectDetailMapper.getRiskPointNumOver3ByFourthId(checkId, ZJpart2FourthId, type3List);
            ZJMap.put("riskPoint", riskPoint);
            glResultBarData1.add(riskPoint);
            List<ProblemCollectDetail> ZJsixthPoints = parProblemCollectDetailMapper.getZJsixthPoints(checkId, ZJpart2FourthId);
            String ZJpointName6Info = JSON.toJSONString(ZJsixthPoints, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray ZJsixthPointsArray = JSONArray.parseArray(ZJpointName6Info);
            double ZJcalculatePoint6 = 0;
            double ZJcalculatePoint66 = 0;
            double ZJcalculateTruePoint = 0;
            for (int y = 0; y < ZJsixthPointsArray.size(); y++) {
                JSONObject ZJsixPointObject = ZJsixthPointsArray.getJSONObject(y);
                int ZJdeductSixthId = ZJsixPointObject.getIntValue("sixthId");
                float ZJdeductPointsSumFloat = parProblemCollectDetailMapper.getdeductSum(checkId, ZJdeductSixthId);
                double ZJdeductPointsSum = Double.valueOf(String.valueOf(ZJdeductPointsSumFloat));
                double ZJtruePoint = Double.parseDouble(ZJsixPointObject.getString("point6"));
                if (ZJtruePoint <= ZJdeductPointsSum) {
                    ZJcalculatePoint66 = 0;
                } else {
                    ZJcalculatePoint66 = ZJtruePoint - ZJdeductPointsSum;
                }
                ZJcalculateTruePoint += ZJtruePoint;
                ZJcalculatePoint6 += ZJcalculatePoint66;
            }
            double ZJnoProblemPoint = 0;
            List<Object> ZJnoProblemSixthIdList = mapperUtils.getUncheckeditemsMapper().getNoProblemSixthId(checkId, ZJpart2FourthId);
            String ZJnoProblemSixthIdInfo = JSON.toJSONString(ZJnoProblemSixthIdList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray ZJnoProblemSixthArray = JSONArray.parseArray(ZJnoProblemSixthIdInfo);
            for (int m = 0; m < ZJnoProblemSixthArray.size(); m++) {
                int ZJnoProblemSixthId = ZJnoProblemSixthArray.getIntValue(m);
                double ZJnoProblem = Double.parseDouble(parSystemMapper.getPoint4ByPoint4Id(ZJnoProblemSixthId));
                ZJnoProblemPoint += ZJnoProblem;
            }
            double ZJcheckItemPoint = (ZJcalculatePoint6 + ZJnoProblemPoint) / (ZJcalculateTruePoint + ZJnoProblemPoint) * 100;
            List<ProblemCollectDetail> ZJcheckItemCalcuList = parProblemCollectDetailMapper.getAllFourthInfo(checkId, ZJpart2FourthId);
            String ZJmaxFourthRiskPoint = pointsCalculate.getMaxRiskPoint(ZJcheckItemCalcuList);
            int ZJmaxFourthRiskPointNum = parProblemCollectDetailMapper.getRiskPointCount(checkId, ZJpart2FourthId, ZJmaxFourthRiskPoint);
            double ZJlimitFourthPoint = Double.parseDouble((mapperUtils.getPointlimitMapper().getLimitPointByInfo(String.valueOf(ZJmaxFourthRiskPointNum), ZJmaxFourthRiskPoint)) == null ? "100" : mapperUtils.getPointlimitMapper().getLimitPointByInfo(String.valueOf(ZJmaxFourthRiskPointNum), ZJmaxFourthRiskPoint));
            if (ZJcheckItemPoint > ZJlimitFourthPoint) {
                ZJcheckItemPoint = ZJlimitFourthPoint;
            }
            String s = df.format(ZJcheckItemPoint);
            ZJMap.put("fourthPoint", s);
            ZJMap.put("aqAllPoint", df.format(allsecondPoint));
            ZJList.add(ZJMap);
            allBarData1.add(Double.parseDouble(s));
            glResultBarData2.add(Double.parseDouble(s));
            ZJallOverPoint = allsecondPoint * 0.7 + ZJcheckItemPoint * 0.3;
            String ZJallOver = df.format(ZJallOverPoint);
            allBarData0.add(Double.parseDouble(ZJallOver));
            ZJMap.put("allOverPoint", ZJallOver);
        }
        dataMap.put("ZJList", ZJList);
        //综合评估柱状图
        try {
            HashMap<String, String> allBarMap = new HashMap<>();
            Map<String, Object> allBarInfos = new HashMap<>();
            Map<String, Object> allBarInfo0 = new HashMap<>();
            allBarInfo0.put("name", "综合评分");
            allBarInfo0.put("color", "rgb(190,190,190)");
            allBarInfo0.put("data", allBarData0);
            Map<String, Object> allBarInfo1 = new HashMap<>();
            allBarInfo1.put("name", "管理行为（权重30%）");
            allBarInfo1.put("color", "rgb(232,137,31)");
            allBarInfo1.put("data", allBarData1);
            Map<String, Object> allBarInfo2 = new HashMap<>();
            allBarInfo2.put("name", "安全文明（权重70%）");
            allBarInfo2.put("color", "rgb(75,67,232)");
            allBarInfo2.put("data", allBarData2);
            Object[] riskBarInfo = new Object[]{allBarInfo0, allBarInfo1, allBarInfo2};
            allBarInfos.put("series", riskBarInfo);
            allBarInfos.put("title", "综合评估结果");
            allBarInfos.put("categories", allBarCategories);
            allBarMap.put("dataSet", JSON.toJSONString(allBarInfos));
            allBarMap.put("width", "718");
            allBarMap.put("height", "468");
            allBarMap.put("index", "8");
            String allBarPic = HttpUtil.post("http://localhost:3000/highcharts", allBarMap, "utf-8");
            dataMap.put("allBarPic", allBarPic.substring(22));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //安全分项评估柱状图
        try {
            HashMap<String, String> aqResultBar = new HashMap<>();
            Map<String, Object> aqResultBarInfos = new HashMap<>();
            Map<String, Object> aqResultBarInfo0 = new HashMap<>();
            aqResultBarInfo0.put("name", "不符合项数量");
            aqResultBarInfo0.put("color", "rgb(75,67,232)");
            aqResultBarInfo0.put("data", aqResultBarData0);
            Map<String, Object> aqResultBarInfo1 = new HashMap<>();
            aqResultBarInfo1.put("name", "3级以上风险数量");
            aqResultBarInfo1.put("color", "red");
            aqResultBarInfo1.put("data", aqResultBarData1);
            Map<String, Object> aqResultBarInfo2 = new HashMap<>();
            aqResultBarInfo2.put("name", "分项得分");
            aqResultBarInfo2.put("color", "#00CD00");
            aqResultBarInfo2.put("data", aqResultBarData2);
            Object[] aqResultBarInfo = new Object[]{aqResultBarInfo0, aqResultBarInfo1, aqResultBarInfo2};
            aqResultBarInfos.put("series", aqResultBarInfo);
            aqResultBarInfos.put("title", "安全实体评估结果");
            aqResultBarInfos.put("subtitle", "安全文明得分:" + allsecondPoint);
            aqResultBarInfos.put("categories", aqResultBarCategories);
            aqResultBar.put("dataSet", JSON.toJSONString(aqResultBarInfos));
            aqResultBar.put("width", "718");
            aqResultBar.put("height", "468");
            aqResultBar.put("index", "1");
            String aqResultBarPic = HttpUtil.post("http://localhost:3000/highcharts", aqResultBar, "utf-8");
            dataMap.put("aqResultBarPic", aqResultBarPic.substring(22));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //管理行为分项评估柱状图
        try {
            HashMap<String, String> glResultBar = new HashMap<>();
            Map<String, Object> glResultBarInfos = new HashMap<>();
            Map<String, Object> glResultBarInfo0 = new HashMap<>();
            glResultBarInfo0.put("name", "不符合项数量");
            glResultBarInfo0.put("color", "rgb(75,67,232)");
            glResultBarInfo0.put("data", glResultBarData0);
            Map<String, Object> glResultBarInfo1 = new HashMap<>();
            glResultBarInfo1.put("name", "3级以上风险数量");
            glResultBarInfo1.put("color", "red");
            glResultBarInfo1.put("data", glResultBarData1);
            Map<String, Object> glResultBarInfo2 = new HashMap<>();
            glResultBarInfo2.put("name", "分项得分");
            glResultBarInfo2.put("color", "#00CD00");
            glResultBarInfo2.put("data", glResultBarData2);
            Object[] glResultBarInfo = new Object[]{glResultBarInfo0, glResultBarInfo1, glResultBarInfo2};
            glResultBarInfos.put("series", glResultBarInfo);
            glResultBarInfos.put("title", "管理行为评估结果");
            glResultBarInfos.put("categories", glResultBarCategories);
            glResultBar.put("dataSet", JSON.toJSONString(glResultBarInfos));
            glResultBar.put("width", "718");
            glResultBar.put("height", "468");
            glResultBar.put("index", "4");
            String glResultBarPic = HttpUtil.post("http://localhost:3000/highcharts", glResultBar, "utf-8");
            dataMap.put("glResultBarPic", glResultBarPic.substring(22));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //三、各分项安全风险情况及改进建议
        List<Object> aqFuzzyList = new ArrayList<>();
        List<Fuzzyresult> aqFuzzyResultInfo = mapperUtils.getFuzzyresultMapper().getAllFuzzyInfoByCheckIdAndTypeAndFirstId(checkId, 4, 1);
        for (int i = 0; i < aqFuzzyResultInfo.size(); i++) {
            Map<String, Object> aqFuzzyMap = new HashMap<>();
            aqFuzzyMap.put("secondIndicator", parSystemMapper.getName4ByName4Id(aqFuzzyResultInfo.get(i).getSecondId()));
            aqFuzzyMap.put("risk1Point", aqFuzzyResultInfo.get(i).getRisk1Point());
            aqFuzzyMap.put("risk2Point", aqFuzzyResultInfo.get(i).getRisk2Point());
            aqFuzzyMap.put("risk3Point", aqFuzzyResultInfo.get(i).getRisk3Point());
            aqFuzzyMap.put("risk4Point", aqFuzzyResultInfo.get(i).getRisk4Point());
            aqFuzzyMap.put("risk5Point", aqFuzzyResultInfo.get(i).getRisk5Point());
            aqFuzzyList.add(aqFuzzyMap);
        }
        dataMap.put("aqFuzzyList", aqFuzzyList);
        List<Object> aqSummaryList = new ArrayList<>();
        List<Summary> aqSummaryInfo = mapperUtils.getSummaryMapper().getSummaryInfo(checkId, 1);
        for (int i = 0; i < aqSummaryInfo.size(); i++) {
            Map<String, Object> aqSummaryMap = new HashMap<>();
            aqSummaryMap.put("No", i + 1);
            aqSummaryMap.put("pName4", parSystemMapper.getName4ByName4Id(aqSummaryInfo.get(i).getFourthId()));
            aqSummaryMap.put("summary", aqSummaryInfo.get(i).getSummary());
            Fuzzyresult fuzzyResult = mapperUtils.getFuzzyresultMapper().selectInfoByCheckIdAndTypeAndNumber(checkId, 4, 1, aqSummaryInfo.get(i).getFourthId());
            try {
                HashMap<String, String> radarMap = new HashMap<>();
                Object[] radarData0 = new Object[]{fuzzyResult.getRisk1Point(), fuzzyResult.getRisk2Point(), fuzzyResult.getRisk3Point(), fuzzyResult.getRisk4Point(), fuzzyResult.getRisk5Point()};
                Object[] radarData1 = new Object[]{fuzzyResult.getRisk1Point(), "", "", "", ""};
                Object[] radarData2 = new Object[]{"", fuzzyResult.getRisk2Point(), "", "", ""};
                Object[] radarData3 = new Object[]{"", "", fuzzyResult.getRisk3Point(), "", ""};
                Object[] radarData4 = new Object[]{"", "", "", fuzzyResult.getRisk4Point(), ""};
                Object[] radarData5 = new Object[]{"", "", "", "", fuzzyResult.getRisk5Point()};
                Object[] radarData6 = new Object[]{"", "", "", "", ""};
                HashMap<String, Object> radarInfoMap = new HashMap<>();
                radarInfoMap.put("data0", radarData0);
                radarInfoMap.put("data1", radarData1);
                radarInfoMap.put("data2", radarData2);
                radarInfoMap.put("data3", radarData3);
                radarInfoMap.put("data4", radarData4);
                radarInfoMap.put("data5", radarData5);
                radarInfoMap.put("data6", radarData6);
                radarMap.put("dataSet", JSON.toJSONString(radarInfoMap));
                radarMap.put("height", "468");
                radarMap.put("width", "718");
                radarMap.put("index", "5");
                String radarPic = HttpUtil.post("http://localhost:3000/echarts", radarMap, "utf-8");
                aqSummaryMap.put("radarPic", radarPic.substring(22));
            } catch (Exception e) {
                e.printStackTrace();
            }
            aqSummaryList.add(aqSummaryMap);
        }
        dataMap.put("aqSummaryList", aqSummaryList);
        List<Object> glSummaryList = new ArrayList<>();
        List<Summary> glSummaryInfo = mapperUtils.getSummaryMapper().getSummaryInfo(checkId, 736);
        for (int i = 0; i < glSummaryInfo.size(); i++) {
            Map<String, Object> glSummaryMap = new HashMap<>();
            glSummaryMap.put("No", i + 1);
            glSummaryMap.put("pName4", parSystemMapper.getName4ByName4Id(glSummaryInfo.get(i).getFourthId()));
            glSummaryMap.put("summary", glSummaryInfo.get(i).getSummary());
            glSummaryList.add(glSummaryMap);
        }
        dataMap.put("glSummaryList", glSummaryList);

        //第二部分 不符合项清单
        List<ProblemCollectDetail> problemList = parProblemCollectDetailMapper.getAllProblemCollectInfoByCheckId(checkId);
        List<Object> section22List = new ArrayList<Object>();
        for (int p = 0; p < problemList.size(); p++) {
            Map<String, Object> problemListMap = new HashMap<String, Object>();
            problemListMap.put("No", p + 1);
            if (problemList.get(p).getSecondId() == 1385) {
                problemListMap.put("pName4", problemList.get(p).getpName4() + "(" + problemList.get(p).getpName3() + ")");
            } else {
                problemListMap.put("pName4", problemList.get(p).getpName4());
            }
            if (problemList.get(p).getIsRemark().equals("N")) {
                problemListMap.put("problemDescription", problemList.get(p).getProblemDescription());
            } else if (problemList.get(p).getIsRemark().equals("Y")) {
                problemListMap.put("problemDescription", problemList.get(p).getRemark());
            }
            problemListMap.put("riskPoint", problemList.get(p).getRiskPoint());
            section22List.add(problemListMap);
        }
        dataMap.put("section22List", section22List);

        //第三部分，安全问题各分项检查情况
        List<Integer> pName1Info = parProblemCollectDetailMapper.getAllName1Id(checkId);
        String name1 = JSON.toJSONString(pName1Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray name1Array = JSONArray.parseArray(name1);
        String section2pName1 = "";
        List<Object> section2List = new ArrayList<Object>();
        for (int b = 0; b < name1Array.size(); b++) {
            Map<String, Object> section2Name1Map = new HashMap<String, Object>();
            List<Object> section2name1List = new ArrayList<Object>();
            String section2name1 = parSystemMapper.getName4ByName4Id(name1Array.getIntValue(b));
            if (section2name1.equals("安全检查")||section2name1.equals("新安全检查")) {
                section2pName1 = "安全问题";
            } else if (section2name1.equals("质量检查")||section2name1.equals("新质量检查")) {
                section2pName1 = "质量问题";
            } else if (section2name1.equals("管理行为")||section2name1.equals("新管理行为")) {
                section2pName1 = "管理体系及管理动作";
            }
            section2Name1Map.put("section2pName1", section2pName1);
            List<Integer> section2Name4Info = parProblemCollectDetailMapper.getAllName4ByName1(checkId, section2name1);
            String section2Name44 = JSON.toJSONString(section2Name4Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray section2Name4Array = JSONArray.parseArray(section2Name44);
            for (int w = 0; w < section2Name4Array.size(); w++) {
                Map<String, Object> section2Name4Map = new HashMap<String, Object>();
                List<Object> section2Name4List = new ArrayList<Object>();
                int section2Name4Id = section2Name4Array.getIntValue(w);
                String section2Name4 = parSystemMapper.getName4ByName4Id(section2Name4Id);
                List<ProblemCollectDetail> section2Name6Info = parProblemCollectDetailMapper.getAllName6InfoByName4(checkId, section2Name4Id, section2name1);
                String section2Name66 = JSON.toJSONString(section2Name6Info, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray section2Name6Array = JSONArray.parseArray(section2Name66);
                for (int c = 0; c < section2Name6Array.size(); c++) {
                    Map<String, Object> section2Name6Map = new HashMap<String, Object>();
                    List<Object> picList = new ArrayList<Object>();
                    JSONObject section2Name6Object = section2Name6Array.getJSONObject(c);
                    section2Name6Map.put("section2pName6No", c + 1);
                    section2Name6Map.put("section2pName6", section2Name6Object.getString("pName6"));
                    section2Name6Map.put("section2pName5", section2Name6Object.getString("pName5"));
                    section2Name6Map.put("section2RiskLevel", section2Name6Object.getString("riskPoint"));
                    section2Name6Map.put("section2CheckPart", section2Name6Object.getString("checkPart"));
                    section2Name6Map.put("section2ProblemNum", section2Name6Object.getString("problemQua"));
                    if (section2Name6Object.getString("isRemark").equals("N")) {
                        section2Name6Map.put("section2problemDescription", section2Name6Object.getString("problemDescription"));
                    } else if (section2Name6Object.getString("isRemark").equals("Y")) {
                        section2Name6Map.put("section2problemDescription", section2Name6Object.getString("remark"));
                    }
                    section2Name6Map.put("section2normsProvison", section2Name6Object.getString("normsProvison"));
                    section2Name6Map.put("section2suggestion", section2Name6Object.getString("suggestion"));
                    String section2picPath = section2Name6Object.getString("picPath");
                    String picName = section2Name6Object.getString("picName");
                    JSONArray ja = JSONArray.parseArray(picName);
                    if (ja.size() == 0) {
                        //String s = MDoc.getImageStr("C:\\Users\\96500\\Desktop\\20190329183836002.png");
                        String s = MDoc.getImageStr("D:\\whutServer\\generatedCharts\\noPic.png");
                        picList.add(s);
                    } else {
                        for (int o = 0; o < ja.size(); o++) {
                            String s = "";
                            if ("prod".equals(profiles.getActives())) {
                                s = MDoc.getImageStr(section2picPath + ja.getString(o));
                            }

                            //String s = MDoc.getImageStr("C:\\Users\\96500\\Desktop\\20190329183836002.png");
                            picList.add(s);
                        }
                    }
                    section2Name6Map.put("picList", picList);
                    section2Name4List.add(section2Name6Map);

                }
                section2Name4Map.put("section2pName4", section2Name4);
                section2Name4Map.put("section2Name4List", section2Name4List);
                section2name1List.add(section2Name4Map);
            }
            section2Name1Map.put("section2Name1List", section2name1List);
            section2List.add(section2Name1Map);
        }
        dataMap.put("section2List", section2List);
        MDoc mdoc = new MDoc();
        String path = FileUtil.getServerFolderPath();
        File f1 = new File(path, "doc");
        if (!f1.exists()) {
            f1.mkdirs();
        }
        mdoc.createDoc(dataMap, path + "\\doc\\" + String.valueOf(dataMap.get("projectName")).replace('#', '号') + "安全可视化报告" + dataMap.get("fileDate") + ".doc", "ftl\\aqVisible.ftl");
        MDoc.docToDocx("D:\\whutServer\\apache-tomcat-8.5.41\\webapps\\ROOT\\doc\\" + String.valueOf(dataMap.get("projectName")).replace('#', '号') + "安全可视化报告" + dataMap.get("fileDate") + ".doc", "D:\\whutServer\\apache-tomcat-8.5.41\\webapps\\ROOT\\doc\\" + String.valueOf(dataMap.get("projectName")).replace('#', '号') + "安全可视化报告" + dataMap.get("fileDate") + ".doc");
        String result = urlProperties.getAddress() + "/doc/" + String.valueOf(dataMap.get("projectName")).replace('#', '号') + "安全可视化报告" + dataMap.get("fileDate") + ".doc";
        return result;
    }
}
